package com.zxisl.util;


import org.apache.log4j.Logger;

/**
 * Created by ade on 2016/11/1.
 */
public class StringUtil {

    public static Logger stringUtilLogger = Logger.getLogger(StringUtil.class);

    /**
     * 根据账号转换为pop3.126.com的形式，这样既可
     *
     * @param username
     * @return
     */
    public static String getHost(String host, String username) {
        try {
            return host + "." + username.substring(username.indexOf("@") + 1);
        } catch (Exception e) {
            stringUtilLogger.info(e.getMessage());
            return "";
        }
    }

    /**
     * 根据账号转换为126.com的形式，这样既可
     *
     * @param username
     * @return
     */
    public static String getStrHost(String username) {
        try {
            return username.substring(username.indexOf("@") + 1);
        } catch (Exception e) {
            stringUtilLogger.info(e.getMessage());
            return "";
        }
    }

    /**
     * 获取server 126，163 etc
     *
     * @param username
     * @return
     */
    public static String getServer(String username) {
        try {
            int beginIndex = username.indexOf("@") + 1;
            int endIndex = username.indexOf(".");
            return username.substring(beginIndex, endIndex);
        } catch (Exception e) {
            stringUtilLogger.info(e.getMessage());
            return "";
        }
    }


}
